package com.example;

import com.example.utils.ConnectionFactoryUtils;
import com.rabbitmq.client.*;

/**
 * @author wangxiyuan
 * @description
 * @createDate 2021/3/24 11:42
 **/
public class NewTask {
    private static final String TASK_QUEUE_NAME = "task_queue";

    public static void main(String[] argv) throws Exception {
        ConnectionFactory factory = ConnectionFactoryUtils.getConnectionFactory();
        try (Connection connection = factory.newConnection();
             Channel channel = connection.createChannel()) {
            /*
              第二个参数durable表示是否持久化队列
             */
            channel.queueDeclare(TASK_QUEUE_NAME, false, false, false, null);
            for (int i = 0; i < 10; i++) {
                AMQP.Confirm.SelectOk selectOk = channel.confirmSelect();
                channel.basicPublish("", TASK_QUEUE_NAME,
                        MessageProperties.PERSISTENT_TEXT_PLAIN,
                        ("testInfo" + i).getBytes("UTF-8"));

            }
        }
    }
}
